package dataStructure;

import java.util.LinkedList;

public class Queue<T> {
    LinkedList<T> linkedList = new LinkedList<>();

    //在队尾插入元素
    public void enQueue(T data) {
        linkedList.addLast(data);
    }

    //删除并返回队首元素
    public T deQueue() {
        if (isEmpty()) throw new RuntimeException("队列为空");
        return linkedList.removeFirst();
    }

    //获取队首元素但不删除
    public T front() {
        if (isEmpty()) throw new RuntimeException("队列为空");
        return linkedList.getFirst();
    }

    //获取长度
    public int size() {
        return linkedList.size();
    }

    //判断是否为空
    public boolean isEmpty() {
        return size() == 0;
    }
}
